'use strict';

const Controller = require('egg').Controller;

const createRule = {
  username:{ type:'string',required:true,message:'用户名必须' }
}

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    let data = { name:'zhangng' }
    await ctx.render('index',{list:data});
  }
  
  // 注册
  async regsiter(){
    const { ctx } = this;
    console.log(ctx.request.body)
    // console.log()
    try {
      ctx.validate(createRule, ctx.request.body)
    } catch (error) {
      ctx.body = {
        code:500,
        message:error.message?error.message:'error',
        data:error
      }
    }
  }
}

module.exports = HomeController;
